﻿using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.DataRegionCreate
{
    public class DataRegionCreateController : Controller
    {
        public IActionResult Word()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            PageOfficeNetCore.Word.WordDocumentWriter wordDoc = new PageOfficeNetCore.Word.WordDocumentWriter();
            //CreateDataRegion方法的三个参数分别代表：将要新建数据区域处的标签的名称、DataRegion的插入位置、与将要创建的DataRegion相关联的书签名称
            //若打开的Word文档中尚无书签或者想在Word文档的开头新建数据区域，则第三那个参数使用“[home]”若想在结尾处新建使用“[end]”
            PageOfficeNetCore.Word.DataRegionWriter dataRegion1 = wordDoc.CreateDataRegion("createDataRegion1", PageOfficeNetCore.Word.DataRegionInsertType.After, "[home]");
            //为创建的DataRegion赋值
            dataRegion1.Value = "新建DataRegion1\r\n";

            PageOfficeNetCore.Word.DataRegionWriter dataRegion2 = wordDoc.CreateDataRegion("createDataRegion2", PageOfficeNetCore.Word.DataRegionInsertType.After, "createDataRegion1");
            dataRegion2.Value = "新建DataRegion2\r\n";

            poCtrl.SetWriter(wordDoc);
            //打开Word文档
            poCtrl.WebOpen("doc/test.doc", PageOfficeNetCore.OpenModeType.docNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }
    }
}